#include <stdio.h>
#include <math.h>
int judge(int a)
{
    int i;
    if(a==1||a==0) return 0;
    for(i = 2;i*i <= a;i++)
    {
        if(a%i==0) return 0;
    }
    return 1;
}
int p(int b)
{
    int count = 0;
    while(b)
    {
        b = b/10;
        count++;
    }
    return count;
}
int main()
{
    int k, n, wei, i, m, d, flag, j;
    scanf("%d",&k);
    while(k--)
    {
        flag = 0;
        scanf("%d",&n);
        wei = p(n);
        if(judge(n)) flag = 1;
        for(i = wei;i > 1;i--)
        {
            d = pow(10,i-1)+1e-6;
            m = n/d;
            n = n-m*d;
            j = p(n);
            if(j == i-1&&judge(n)) flag = 1;
            else
            {
                flag = 0;
                break;
            }
        }
        if(flag) printf("Yes\n");
        else printf("No\n");
    } 
}
